<template>
  <el-header class="me-area">
    <el-row class="me-header">
      <el-col :span="4" class="me-header-left">
        <router-link to="/home" class="me-title">
          <img src="../../../assets/imgs/logo1.png" />
        </router-link>
      </el-col>

      <el-col v-if="!simple" :span="16">
        <el-menu
          :router="true"
          menu-trigger="click"
          active-text-color="#5FB878"
          :default-active="activeIndex"
          mode="horizontal"
        >
          <el-menu-item index="/main-one">首页</el-menu-item>
          <el-menu-item index="/noticeInfo" :route="{ name: 'noticeInfo' ,params:{type:1} }">公告信息</el-menu-item>
          <el-menu-item index="/basicData" :route="{ path: `/basicData/${0}` }">标案数据</el-menu-item
          >
          <el-menu-item index="/organize-user">组织人员</el-menu-item>

          <el-col :span="4" :offset="4">
            <el-menu-item index="/comment"
              ><i class="el-icon-edit"></i>留言板</el-menu-item
            >
          </el-col>
        </el-menu>
      </el-col>

      <template v-else>
        <slot></slot>
      </template>

      <el-col :span="4">
        <el-menu
          :router="true"
          menu-trigger="click"
          mode="horizontal"
          active-text-color="#5FB878"
        >
          <template v-if="!user.login">
            <el-menu-item index="/login">
              <el-button type="text">登录</el-button>
            </el-menu-item>
            <el-menu-item index="/register">
              <el-button type="text">注册</el-button>
            </el-menu-item>
          </template>

          <template v-else>
            <el-submenu index>
              <template slot="title">
                <img class="me-header-picture" :src="user.avatar" />
              </template>
              <el-menu-item index @click="dashboard"
                ><i class="el-icon-s-home"></i>后台管理</el-menu-item
              >
              <el-menu-item index @click="logout"
                ><i class="el-icon-back"></i>退出</el-menu-item
              >
            </el-submenu>
          </template>
        </el-menu>
      </el-col>
    </el-row>
    <!-- <el-row class="me-header">
      <Banner></Banner>
    </el-row> -->
  </el-header>
</template>

<script>
// import Banner from "./Banner.vue";

export default {
  name: "BaseHeader",
  // components: {Banner},
  props: {
    activeIndex: String,
    simple: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {
    user() {
      let login = this.$store.getters.name.length !== 0;
      let avatar = this.$store.getters.avatar;
      return {
        login,
        avatar,
      };
    },
  },
  methods: {
    dashboard() {
      this.$router.push("/dashboard");
    },
    logout() {
      let that = this;
      this.$store
        .dispatch("user/logout")
        .then(() => {
          this.$router.go(0);
        })
        .catch((error) => {
          if (error !== "error") {
            that.$message({ message: error, type: "error", showClose: true });
          }
        });
    },
  },
};
</script>

<style scoped>
.el-header {
  position: fixed;
  z-index: 1024;
  min-width: 100%;
  box-shadow: 0 2px 3px hsla(0, 0%, 7%, 0.1), 0 0 0 1px hsla(0, 0%, 7%, 0.1);
}

.me-header-left {
  align-content: center;
}
.me-title {
  align-content: center;
}
.me-title img {
  height: auto;
  width: 100%;
}

.me-header-picture {
  width: 36px;
  height: 36px;
  border: 1px solid #ddd;
  border-radius: 50%;
  vertical-align: middle;
  background-color: #5fb878;
}
</style>
